//
//  ViewController.m
//  TestSDWebImage
//
//  Created by 吴志勇 on 2020/3/11.
//  Copyright © 2020 wzy. All rights reserved.
//

#import "ViewController.h"
#import "UIImageView+WebCache.h"
#import "SDWebImageManager.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *downloadImageView;

/* 注释 */
@property (nonatomic, strong) NSCache *cache;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSString *str = @"https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png";
    
    NSString *Urlstr = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSURL *url = [NSURL URLWithString:Urlstr];
     [self.downloadImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"1"] options:SDWebImageAllowInvalidSSLCertificates completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        NSLog(@"%@",error);
    }];
    
    
//    [SDWebImageManager sharedManager].imageCache
}


//存数据
- (void)addData{
    for (int i = 0; i < 10; i++) {
        NSData *data = [NSData data];
        [self.cache setObject:data forKey:@(i)];
    }
}

//取数据
- (void)checkData{
    NSData *data = [self.cache objectForKey:@(1)];
    NSLog(@"%@",data);
}


#pragma mark -------Lazy

- (NSCache *)cache {
    if (!_cache) {
        _cache = [[NSCache alloc] init];
        _cache.totalCostLimit = 5;//总成本数是5，如果发现存的数据超过成本那么自动会回收之前存的对象
//        _cache.countLimit = 10;//最多存是个数据
    }
    return  _cache;
}


@end
